#!/bin/bash

if [ `id -u` != 0 ] ; then
    echo "you are not root! press a key, not shift/ctrl/alt"
    read -n 1 -s
    exit 1
fi

#run this as root or with sudo
#set destination drive to wipe with zeroes (ALL DATA IS LOST!) but this is not like a shreder! it just zeroes(instead of random) the data so it doesn't look like it's encrypted
destdrive=/dev/sdd

#8960
#10714
#4162
#6406
#3837 #25min 31 sec
#4761 #33min 26 sec
#1340 #9min 58sec
#2459 #18min 27sec
#4776 #37min 54sec
#3767 #32min 27sec #51182 after this
#989 #8min 57sec #52171 after this
#direct i/o enabled past this point(much better than cached!):
#2563 86gb #54734
#1571 53gb #34min 36sec #56035 after (was doing another dd in backg wasn't aware of)
#3536 119gb #41min 41sec #3536 out; #completed: 59616 blocks of 32MiB on 2TB WDC WD20EARS

leftfrom=59616

#time 
dd if=/dev/zero of=$destdrive bs=32M seek=$leftfrom iflag=fullblock,nonblock oflag=direct,nonblock,sync conv=fsync,nocreat,notrunc & pid=$!
echo "* use this to make it dump stats:"
echo sudo watch -n10 kill -USR1 $pid
echo "* use the following to check hdd temperature(field 194 for WDC WD20EARS):"
echo sudo hddtemp --debug $destdrive
echo "* when ready to stop it, use the following and wait until this ends:"
echo sudo kill $pid
time wait $pid

#2 or 3 types of flushes
sync
hdparm -f /dev/sdd
sleep 2s
hdparm -F /dev/sdd
sleep 1s

#show power status
hdparm -C /dev/sdd
#power down into sleep mode
sleep 2s
hdparm -Y /dev/sdd
sleep 3s
#show power status
hdparm -C /dev/sdd

